package lib;


public class SpCorrCount {
	
	public static double whole_spectrum(double[][] exper_sp,double[][] theor_sp){
		double fragmentError=0.3;
		double correlation = 0;
		int array_max_length= exper_sp.length+theor_sp.length;
		//publicMethod.ArrayManipulation.printArrayT(this.intensity_array);
		//publicMethod.ArrayManipulation.printArrayT(spe.intensity_array);
		double[] align_array1 = new double[array_max_length];
		double[] align_array2 = new double[array_max_length];
		int index1 =0, index2 =0, index=0;
		while(index1<exper_sp.length&&index2<theor_sp.length){
			if(exper_sp[index1][0]<theor_sp[index2][0]-fragmentError){
				align_array1[index]=exper_sp[index1][1];
				align_array2[index++] = 0;
				index1++;
			}
			else if(exper_sp[index1][0]-fragmentError > theor_sp[index2][0]){
				
				align_array1[index] = 0;
				align_array2[index++]=theor_sp[index2][1];
				index2++;
				
			}
			else{
				
				align_array1[index] = exper_sp[index1][1];
				align_array2[index++]=theor_sp[index2][1];
				index1++;
				index2++;
			}
			
		}
		for(int i=index1;i<exper_sp.length;i++){
			align_array1[index] = exper_sp[i][1];;
			align_array2[index++]=0;
		}
		for(int i=index2;i<theor_sp.length;i++){
			align_array1[index] = 0;
			align_array2[index++]=theor_sp[i][1];
		}
		double[][] a = ArrayManipulation.array_trim(align_array1, align_array2);
		correlation = Statistics.Correlation(a[0], a[1]);
		
		return correlation;
		


   }//whole
	
}
